﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightGame
{
    public class Powerup : AnimatedGameObject
    {
        public const string POWERUP = "powerup";
        public const int PLAYER_Z = 10;
        protected const double SPEED = 75;
        protected static ResourcePool<Powerup> resourcePool = new ResourcePool<Powerup>();
        public delegate void PowerupLogic(double dt);
        protected PowerupLogic powerupLogic = null;
        protected int score = 0;

        static public Powerup UnusedPowerup
        {
            get
            {
                return resourcePool.UnusedObject;
            }
        }

        public int Score
        {
            get
            {
                return score;
            }
        }

        public Powerup()
        {

        }

        public override void enterFrame(double dt)
        {
            base.enterFrame(dt);

            if (inUse)
            {
                if (powerupLogic != null) powerupLogic(dt);
            }
        }

        public Powerup startupBasicPowerup(Point dimensions, AnimationData animationData, int score, int zLayer)
        {
            base.startupAnimatedGameObject(dimensions, animationData, zLayer, false);
            powerupLogic = new PowerupLogic(this.basicPowerupLogic);
            this.collisionName = POWERUP;
            this.score = score;
            return this;
        }

        public override void shutdown()
        {
            base.shutdown();
            powerupLogic = null;
        }

        protected void basicPowerupLogic(double dt)
        {
            Position = new Point(Position.X, Position.Y + SPEED * dt);
            offscreenCheck();
        }

        public override void collision(GameObject other)
        {
            base.collision(other);
                ApplicationManager.Instance.Score += score;
            this.shutdown();
        }
    }
}
